package com.example.controller;

import com.example.model.UserInfo;
import com.example.service.LogService;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RequestMapping("/propaga")
@RestController
public class PropagationController {
    @Autowired
    private UserService userService;
    @Autowired
    private LogService logService;

    @Transactional(propagation = Propagation.REQUIRED)//默认的事务传播级别
    @RequestMapping("/p1")
    public Boolean p1(UserInfo userInfo){
        //用户注册
        Integer result1 = userService.registerUser(userInfo);
        System.out.println("注册成功，影响行数："+result1);
        //插入日志表
        Integer result2 = logService.insert(userInfo.getUserName(),"用户注册");
        System.out.println("插入成功，影响行数："+result2);
        return true;
    }
}
